use "$temp/nlsy_moment_data", clear
tab coll_cat
drop if hgc_20<12 //drop hs dropouts
drop if coll_cat == . //drop if educational category missing
drop if hgc_final == . //drop if final schooling missing

//normalizing level: age-19 wages for people who don't enroll in college
egen wage_early = rowmean(wage_18 wage_19 wage_20)
su wage_early [fw = weight_19] if coll_cat == 0
local div = `r(mean)'
drop wage_early

//prepare for collapsing loop
keep uniqid coll_cat hgc_final_comp weight* wage* ability
reshape long wage_ weight_, i(uniqid) j(age)
replace wage_ = wage_/`div'

//collapse: age profiles over enrollment and ability
forval a = 23/35{
	preserve
	keep if age>=(`a'-2) & age<=(`a' + 2) //5-year age bin
	collapse (mean) wage [fw = weight], by(ability hgc_final_comp)
	gen age = `a'
	save "$temp/nlsy_bin_`a'", replace
	restore
}

//mash together
clear
forval a = 23/35{
	append using "$temp/nlsy_bin_`a'"
}

//by ability
forval i = 1/3{
	twoway connected wage age if ability == `i' & hgc_final_comp == 1 || connected wage age if ability == `i' & hgc_final_comp == 2 || connected wage age if ability == `i' & hgc_final_comp == 3, ///
	bgcolor(white) graphregion(color(white)) xtitle("Age") ytitle("Mean Wage") legend(lab(1 "HS Only") lab(2 "Some Coll") lab(3 "College")) ylabel(0(0.5)4, nogrid)
	graph export "$output/nlsy_profile_ability_`i'.png", replace
	graph close
}

sort ability hgc_final age
export delimited "$output/nlsy_profiles.csv", replace novarn
save "$temp/nlsy_wage_profiles", replace


*******overall*****
use "$temp/nlsy_moment_data", clear
tab coll_cat
drop if hgc_20<12 //drop hs dropouts
drop if coll_cat == . //drop if educational category missing
drop if hgc_final == . //drop if final schooling missing

//normalizing level: age-19 wages for people who don't enroll in college
egen wage_early = rowmean(wage_18 wage_19 wage_20)
su wage_early [fw = weight_19] if coll_cat == 0
local div = `r(mean)'
drop wage_early

//prepare for collapsing loop
keep uniqid coll_cat hgc_final_comp weight* wage* ability
reshape long wage_ weight_, i(uniqid) j(age)
replace wage_ = wage_/`div'

//collapse: age profiles over enrollment and ability
forval a = 23/35{
	preserve
	keep if age>=(`a'-2) & age<=(`a' + 2) //5-year age bin
	collapse (mean) wage [fw = weight], by(hgc_final_comp)
	gen age = `a'
	save "$temp/nlsy_bin_`a'", replace
	restore
}

//mash together
clear
forval a = 23/35{
	append using "$temp/nlsy_bin_`a'"
}

//by ability
twoway connected wage age if hgc_final_comp == 1 || connected wage age if hgc_final_comp == 2 || connected wage age if hgc_final_comp == 3, ///
bgcolor(white) graphregion(color(white)) xtitle("Age") ytitle("Mean Wage") legend(lab(1 "HS Only") lab(2 "Some Coll") lab(3 "College")) ylabel(0(0.5)4, nogrid)
graph export "$output/nlsy_profile_all.png", replace
graph close


sort hgc_final age
export delimited "$output/nlsy_profiles_all.csv", replace novarn
save "$temp/nlsy_wage_profiles_all", replace



//end of do-file
